package com.gzx.plugin.tjzy.modular.gzxcase.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.gzxcase.bo.GzxCaseDetailQueryBo;
import com.gzx.plugin.tjzy.modular.gzxcase.bo.GzxCaseEditBo;
import com.gzx.plugin.tjzy.modular.gzxcase.bo.GzxCaseQueryBo;
import com.gzx.plugin.tjzy.modular.gzxcase.bo.GzxChangeCaseBo;
import com.gzx.plugin.tjzy.modular.gzxcase.vo.GzxCaseDetailJsonVo;
import com.gzx.plugin.tjzy.modular.gzxcase.vo.GzxCaseDetailVo;
import com.gzx.plugin.tjzy.modular.gzxcase.vo.GzxCaseVo;
import com.gzx.plugin.tjzy.modular.gzxcase.service.GzxCaseService;
import com.gzx.plugin.tjzy.modular.word.mediation.vo.GzxWordMediationVo;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.annotation.CommonNoRepeat;
import vip.xiaonuo.common.pojo.CommonResult;

import java.io.IOException;
import java.util.List;

/**
 * @author zjt
 * @description
 * @date 2024/12/3 14:28
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/case")
public class GzxCaseController {

    private final GzxCaseService caseService;

    @PostMapping("/pageList")
    public CommonResult<Page<GzxCaseVo>> pageList(@RequestBody GzxCaseQueryBo caseQueryBo) throws IllegalAccessException {
        return CommonResult.data(caseService.pageList(caseQueryBo));
    }

    /**
     * 获取案件详情页贷款信息
     */
    @PostMapping("/pageListDetail")
    public CommonResult<Page<GzxCaseDetailVo>> pageListDetail(@RequestBody GzxCaseDetailQueryBo caseDetailQueryBo) {
        return CommonResult.data(caseService.pageListDetail(caseDetailQueryBo));
    }

    /**
     * 获取案件详情页贷款信息
     */
    @GetMapping("/getCaseDetailJson/{caseDetailId}")
    public CommonResult<List<GzxCaseDetailJsonVo>> getCaseDetailJson(@PathVariable("caseDetailId") Long caseDetailId) {
        return CommonResult.data(caseService.getCaseDetailJson(caseDetailId));
    }

    @CommonLog("案件导入")
    @PostMapping("/importCase")
    @CommonNoRepeat
    public CommonResult<Void> importCase(@RequestParam("file") MultipartFile multipartFile, @RequestParam("projectCode") String projectCode) {
        caseService.importCase(multipartFile, projectCode);
        return CommonResult.ok();
    }

    /**
     * 获取上一下一案件
     */
    @PostMapping("/changeCase")
    public CommonResult<GzxCaseVo> changeCase(@RequestBody GzxChangeCaseBo changeCaseBo) {
        return CommonResult.data(caseService.changeCase(changeCaseBo));
    }

    /**
     * 根据甲方系统主键获取案件详情
     */
    @GetMapping("/getCaseByParentBusinessId/{parentBusinessId}")
    public CommonResult<GzxCaseVo> getCaseByParentBusinessId(@PathVariable String parentBusinessId) {
        return CommonResult.data(caseService.getCaseByParentBusinessId(parentBusinessId));
    }

    /**
     * 根据甲方系统主键获取案件详情
     */
    @PostMapping("/edit")
    @CommonNoRepeat
    public CommonResult<Void> edit(@RequestBody GzxCaseEditBo caseEditBo) {
        caseService.update(caseEditBo);
        return CommonResult.ok();
    }

    /**
     * 根据甲方系统主键获取案件详情
     */
    @PostMapping("/exportMyCaseLiaison")
    @CommonNoRepeat
    public void exportMyCaseLiaison(@RequestBody GzxCaseQueryBo caseQueryBo, HttpServletResponse response) throws IllegalAccessException, IOException {
        caseService.exportMyCaseLiaison(caseQueryBo, response);
    }

    /**
     * 根据案件ID获取调解协议数据
     */
    @GetMapping("/getWordMediationData/{caseId}")
    public CommonResult<GzxWordMediationVo> getWordMediationData(@PathVariable Long caseId) {
        return CommonResult.data(caseService.getWordMediationData(caseId));
    }
}
